package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.LabUiAnnotation;
import com.miyake.dsp.osa.lab.NoiseRemoverSetting;

@LabUiAnnotation(caption="Noise Remover")
public class NoiseGateWrapper extends Calculator {
	public static final String INPUT = "Input";
	public static final String OUTPUT = "Output";
	
	private NoiseRemoverSetting setting;

	public NoiseGateWrapper(NoiseRemoverSetting setting) {
		this.setting = setting;
		initInput(INPUT);
		initOutput(OUTPUT);
	}
	@Override
	public synchronized void process() {
		double[] d = this.getInput(INPUT).getRealPart();
		double[] ret = new double[d.length];
		for (int i = 0; i < d.length; i++) {
			if (d[i] < setting.getThreshold()) {
				ret[i] = 0.0;
			}
			else {
				ret[i] = d[i];
			}
		}
		this.setOutput(OUTPUT, ret);
	}

	@Override
	public Object getSetting() {
		return setting;
	}

}
